package feign.ethan.springCloud.config;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class AsyncTest {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Async
    public void hello(String name){
        //这里使用logger 方便查看执行的线程是什么
        logger.info("异步线程启动 started."+name);
    }

    @Test
    void contextLoads() throws InterruptedException {
        AsyncTest asyncTest = new AsyncTest();
        asyncTest.hello("afsasfasf");
        //一定要休眠 不然主线程关闭了，子线程还没有启动
        Thread.sleep(1000);
    }
}